package cn.xf.service.impl;

import cn.xf.dao.IRoleDao;
import cn.xf.domain.Role;
import cn.xf.service.IRoleService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author xiaofu
 * @date 2021-05-18 12:08
 * @email dearaf@163.com
 */
@Service
@Transactional
public class RoleServiceImpl implements IRoleService {

    @Autowired
    private IRoleDao roleDao;


    @Override
    public List<Role> findAll() {

        return roleDao.findAll();
    }

    @Override
    public void save(Role role) {
        roleDao.save(role);
    }

    @Override
    public List<Role> findOtherRole(String id) {
        return roleDao.findOtherRole(id);
    }

    @Override
    public Role findById(String roleId) {
        return roleDao.findById(roleId);
    }

    @Override
    public void addPermissionToRole(String roleId, String[] permissionIds) {
        for(String permissionId : permissionIds){
            roleDao.addPermissionToRole(roleId,permissionId);
        }

    }

    @Override
    public List<Role> findAllByPage(Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        return roleDao.findAll();
    }
}
